package ai.plantdata.dao.util;

import ai.plantdata.dao.dto.AssociateDTO;
import ai.plantdata.dao.dto.ConceptAssociateConceptTable;
import ai.plantdata.dao.dto.EntityAssociateConceptTable;
import ai.plantdata.dao.dto.EntityExpandTable;
import ai.plantdata.dao.dto.UnrelatedConceptSeparateTab;
import ai.plantdata.dao.dto.UnrelatedEntitySeparateTab;
import ai.plantdata.vo.SeparateTable;

import java.util.Map;

/**
 * @Author: WangHui
 * @Date: 2021/7/19 16:00
 * @Description:
 */
public class BeanTransform {

    private static AssociateDTO setAssociateDTO(SeparateTable separateDTO) {
        AssociateDTO associateDTO = new AssociateDTO();
        associateDTO.setTableName(separateDTO.getAssociationTableName());
        Map<String, SeparateTable> map = separateDTO.getMap();
        SeparateTable separateTable = map.get(separateDTO.getAssociationTableName());
        associateDTO.setNameField(separateTable.getNameField());
        associateDTO.setMeanTagField(separateTable.getMeanTagField());
        associateDTO.setAssociateField(separateDTO.getAssociationTableField());
        return associateDTO;
    }

    public static ConceptAssociateConceptTable separateTableToConceptAssociateConceptTable(SeparateTable separateDTO) {
        ConceptAssociateConceptTable conceptAssociateConceptTable = new ConceptAssociateConceptTable();
        conceptAssociateConceptTable.setTableName(separateDTO.getTableName());
        conceptAssociateConceptTable.setNameField(separateDTO.getNameField());
        conceptAssociateConceptTable.setMeanTagField(separateDTO.getMeanTagField());
        conceptAssociateConceptTable.setAssociationField(separateDTO.getAssociationField());
        conceptAssociateConceptTable.setAssociateDTO(setAssociateDTO(separateDTO));
        return conceptAssociateConceptTable;
    }

    public static EntityAssociateConceptTable separateTableToEntityAssociateConceptTable(SeparateTable separateDTO) {
        EntityAssociateConceptTable table = new EntityAssociateConceptTable();
        table.setTableName(separateDTO.getTableName());
        table.setNameField(separateDTO.getNameField());
        table.setMeanTagField(separateDTO.getMeanTagField());
        table.setFieldName(separateDTO.getAttrList());
        table.setAssociationField(separateDTO.getAssociationField());
        table.setAssociateDTO(setAssociateDTO(separateDTO));
        return table;
    }

    public static UnrelatedConceptSeparateTab separateTableToUnrelatedConceptSeparateTab(SeparateTable separateDTO) {
        UnrelatedConceptSeparateTab unrelatedConceptSeparateTab = new UnrelatedConceptSeparateTab();
        unrelatedConceptSeparateTab.setName(separateDTO.getName());
        unrelatedConceptSeparateTab.setNameField(separateDTO.getNameField());
        unrelatedConceptSeparateTab.setMeanTag(separateDTO.getMeanTag());
        unrelatedConceptSeparateTab.setMeanTagField(separateDTO.getMeanTagField());
        unrelatedConceptSeparateTab.setTableName(separateDTO.getTableName());
        return unrelatedConceptSeparateTab;
    }

    public static UnrelatedEntitySeparateTab separateTableToUnrelatedEntitySeparateTab(SeparateTable separateDTO) {
        UnrelatedEntitySeparateTab unrelatedConceptSeparateTab = new UnrelatedEntitySeparateTab();
        unrelatedConceptSeparateTab.setTableName(separateDTO.getTableName());
        unrelatedConceptSeparateTab.setNameField(separateDTO.getNameField());
        unrelatedConceptSeparateTab.setMeanTagField(separateDTO.getMeanTagField());
        unrelatedConceptSeparateTab.setFieldName(separateDTO.getAttrList());
        unrelatedConceptSeparateTab.setConceptName(separateDTO.getName());
        unrelatedConceptSeparateTab.setConceptMeanTag(separateDTO.getMeanTag());
        return unrelatedConceptSeparateTab;
    }

    public static EntityExpandTable separateTableToEntityExpandTable(SeparateTable separateDTO) {
        EntityExpandTable table = new EntityExpandTable();
        table.setTableName(separateDTO.getTableName());
        Map<String, SeparateTable> map = separateDTO.getMap();
        String associationTableName = separateDTO.getAssociationTableName();
        SeparateTable separateTable = map.get(associationTableName);
        table.setTableEnum(separateTable.getStatus());
        table.setFiledNames(separateDTO.getAttrList());
        table.setAssociationField(separateDTO.getAssociationField());
        table.setAssociateDTO(setAssociateDTO(separateDTO));
        return table;
    }
}
